﻿
Public Class MenuTreeView
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tvMenu.Nodes.Clear()
        Dim menucon As DataTable = Menu.LoadLoaiSP()
        Dim menucha As DataTable = Menu.LoadDanhMucSP()
        Dim tmpMenu As DataTable = menucon.Clone()
        For i = 0 To menucha.Rows.Count - 1
            Dim node As New TreeNode
            node.Text = menucha.Rows(i)("TenDanhMuc").ToString()
            node.NavigateUrl = "../ProductList.aspx?idList=" + menucha.Rows(i)("MaDanhMuc").ToString()
            Dim b = Int32.Parse(menucha.Rows(i)(0).ToString())
            Dim rows As DataRow() = menucon.Select("MaDanhMuc=" + b.ToString())
            For Each Row As DataRow In rows
                Dim row1 As DataRow = tmpMenu.NewRow()
                For c = 0 To Row.ItemArray.Length - 1
                    row1(c) = Row.ItemArray(c).ToString()
                Next
                tmpMenu.Rows.Add(row1)
            Next
            If tmpMenu.Rows.Count > 1 Then
                For a = 0 To tmpMenu.Rows.Count - 1
                    Dim nodechild As New TreeNode()
                    nodechild.Text = tmpMenu.Rows(a)("TenLoai").ToString()
                    nodechild.NavigateUrl = node.NavigateUrl + "&idKind=" + tmpMenu.Rows(a)("MaLoai").ToString()
                    node.ChildNodes.Add(nodechild)
                Next
            End If
            tmpMenu = menucon.Clone()
            tvMenu.Nodes.Add(node)
            tvMenu.ExpandAll()
        Next
    End Sub

End Class